package com.fhsk.file.common.vo;

import com.fhsk.file.common.utils.DateUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@Data
public class AjaxResult implements Serializable {
    //如果接口错误，则有值
    private Integer code = 200;
    //时间
    private String time;
    //消息
    private String msg;
    //如果接口正常，则data存返回的数据，如果接口错误，则data为空
    private Object data;
    //true：成功 代表本次请求是否成功
    private Boolean success;

    public AjaxResult() {

    }

    public static AjaxResult success() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg("成功");
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        return ajaxResult;
    }

    public static AjaxResult success(Object data) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg("成功");
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success(Object data, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setMsg(msg);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setData(data);
        return ajaxResult;
    }

    public static AjaxResult success(Integer code, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(true);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult fail() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg("失败");
        ajaxResult.setCode(500);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        return ajaxResult;
    }


    public static AjaxResult fail(Integer code, String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setCode(code);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult fail(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(500);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult failNoTime(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(500);
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult warn() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg("失败");
        ajaxResult.setCode(300);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        return ajaxResult;
    }

    public static AjaxResult warn(String msg) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(300);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg(msg);
        return ajaxResult;
    }

    public static AjaxResult unload() {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setCode(401);
        ajaxResult.setTime(DateUtil.formatDatetime(new Date()));
        ajaxResult.setSuccess(false);
        ajaxResult.setMsg("请先登录");
        return ajaxResult;
    }

}
